﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Sunlit.Business.Configuration;
using Sunlit.Business.Web;

namespace Sunlit.Business.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class BusinessDbContextFactory : IDesignTimeDbContextFactory<BusinessDbContext>
    {
        public BusinessDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<BusinessDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            BusinessDbContextConfigurer.Configure(builder, configuration.GetConnectionString(BusinessConsts.ConnectionStringName));

            return new BusinessDbContext(builder.Options);
        }
    }
}
